var express = require('express');
var router = express.Router();

// 数据库配置
let modle = require("../modle/db")

router.get("/index")


router.post("/add", (req, res) => { 
    let { name, sex, age } = req.body
    // console.log(name,sex,age);

    let sql = `insert into student (姓名,性别,年龄) value ("${name}","${sex}",${age})`
    
    modle.query(sql, (err) => {
        if (err) {
            console.log("失败");
        } else { 
            res.send("index.html")
        }
    })

})

router.post("/edit", (req, res) => { 
    let { name, sex, age } = req.body
    // console.log(name,sex,age);

    let sql = `insert into student (姓名,性别,年龄) value ("${name}","${sex}",${age})`
    
    modle.query(sql, (err) => {
        if (err) {
            console.log("失败");
        } else { 
            res.send("index.html")
        }
    })

})


module.exports = router;